// based on Fast_rand from Listing 1 at:
// http://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/

package oboe.utils;

import flash.Vector;

class RandomInt
{
private static var seed:UInt=0;

public static function srand( nseed:UInt ):Int
{
	seed = (214013*nseed+2531011); 
	return (seed>>16)&0x7FFF; 
}

public static function rand():Int
{
	seed = (214013*seed+2531011); 
	return (seed>>16)&0x7FFF; 
}

public static function srandf( nseed:Float ):Float
{
	seed = (214013*int(nseed*1000)+2531011); 
	return ((seed>>16)&0x7FFF)/32767.0; 
}

public static function randf():Float
{
	seed = (214013*seed+2531011); 
	return ((seed>>16)&0x7FFF)/32767.0; 
}

private static var pool:Vector<Float>;
public static function tsrandf( nseed:Int ):Float
{
	if( !pool )
	{
	pool = new Vector<Float>(0x40, true);
	var tseed:UInt = (214013*int(seed)+2531011);
	for( var i:Int=0; i<0x40; ++i )
	{
		tseed = (tseed>>16)&0x7FFF; 
		pool[ i ] = tseed / 32767.0;
		tseed = (214013*int(tseed)+2531011); 
	}
	}
	return pool[ nseed&0x3F ];
}
}